﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Marbles.Core.Content.Analytics
{
    public class AddFreeStats : WebControl, IAnalyticsControl
    {
        public string EngineName
        {
            get { return "addfreestats"; }
        }

        public string Title
        {
            get { return "AddFreeStats"; }
        }

        public string SupportUrl
        {
            get { return "http://www.addfreestats.com/"; }
        }

        public Dictionary<string, string> Settings
        {
            get
            {
                return _settings;
            }
            set
            {
                _settings = value;
            }
        }

        private Dictionary<string, string> _settings = new Dictionary<string, string>();

        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute("type", "text/javascript");
            writer.AddAttribute("language", "javascript");
            writer.RenderBeginTag(HtmlTextWriterTag.Script);
            writer.Write("var AFS_Account = '" + Settings["ACCOUNT"] + "';");
            writer.Write("var AFS_Tracker = 'auto';");
            writer.Write("var AFS_Server = 'www';");
            writer.Write("var AFS_Page = document.title;");
            writer.Write("var AFS_Url = window.location.href;");
            writer.RenderEndTag();

            writer.AddAttribute("type", "text/javascript");
            writer.AddAttribute("language", "javascript");

            writer.AddAttribute("src", "http://www.addfreestats.com/cgi-bin/afstrack.cgi?usr=" + this.Settings["ACCOUNT"]);
            writer.RenderBeginTag(HtmlTextWriterTag.Script);

            writer.RenderEndTag();
        }

    }
}
